//
//  ViewController.m
//  11104
//
//  Created by student on 16/2/29.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIPageControl *pagecontrol;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIButton *button1 = [[UIButton alloc]initWithFrame:CGRectMake(0, 60, 60,50)];
    [button1 setTitle:@"新闻1" forState:UIControlStateNormal];
    [button1 setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    UIButton *button2 = [[UIButton alloc]initWithFrame:CGRectMake(75, 60,  60,50)];
    [button2 setTitle:@"新闻2" forState:UIControlStateNormal];
     [button2 setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    UIButton *button3 = [[UIButton alloc]initWithFrame:CGRectMake(75*2, 60,  60,50)];
    [button3 setTitle:@"新闻3" forState:UIControlStateNormal];
     [button3 setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    UIButton *button4 = [[UIButton alloc]initWithFrame:CGRectMake(75*3, 60,  60,50)];
   [button4 setTitle:@"新闻4" forState:UIControlStateNormal];
    [button4 setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    UIButton *button5 = [[UIButton alloc]initWithFrame:CGRectMake(75*4, 60,  60,50)];
  [button5 setTitle:@"新闻5" forState:UIControlStateNormal];
    [button5 setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    UIButton *button6 = [[UIButton alloc]initWithFrame:CGRectMake(75*5, 60,  60,50)];
   [button6 setTitle:@"新闻6" forState:UIControlStateNormal];
    [button6 setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    UIButton *button7 = [[UIButton alloc]initWithFrame:CGRectMake(75*6, 60,  60,50)];
  [button7 setTitle:@"新闻7" forState:UIControlStateNormal];
    [button7 setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    UIButton *button8 = [[UIButton alloc]initWithFrame:CGRectMake(75*7, 60,  60,50)];
   [button8 setTitle:@"新闻8" forState:UIControlStateNormal];
     [button8 setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    UIButton *button9 = [[UIButton alloc]initWithFrame:CGRectMake(75*8, 60,  60,50)];
    [button9 setTitle:@"新闻9" forState:UIControlStateNormal];
     [button9 setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    UIButton *button10 = [[UIButton alloc]initWithFrame:CGRectMake(75*9, 60,  60,50)];
  [button10 setTitle:@"新闻10" forState:UIControlStateNormal];
    [button10 setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
   
    [self.scrollView addSubview:button1];
    [self.scrollView addSubview:button2];
    [self.scrollView addSubview:button3];
    [self.scrollView addSubview:button4];
    [self.scrollView addSubview:button5];
    [self.scrollView addSubview:button6];
    [self.scrollView addSubview:button7];
    [self.scrollView addSubview:button8];
    [self.scrollView addSubview:button9];
    [self.scrollView addSubview:button10];
    [self.view addSubview:self.scrollView];
    [self.view addSubview:self.pagecontrol];
    self.pagecontrol.frame = CGRectMake(375/2, 60, 50, 50);
    self.scrollView.frame = CGRectMake(0,0, 400, 119);
    self.scrollView.contentSize = CGSizeMake(750, 119);
    self.scrollView.bounces = YES;
    self.scrollView.indicatorStyle = UIScrollViewIndicatorStyleBlack;
    self.scrollView.backgroundColor = [UIColor blackColor];
    self.scrollView.pagingEnabled = YES;
    
    self.scrollView.delegate = self;
    
    [self.view addSubview:self.pagecontrol];
    
    self.pagecontrol.numberOfPages = 2;
    self.pagecontrol.currentPage = 0;

    self.pagecontrol.pageIndicatorTintColor = [UIColor yellowColor];
    self.pagecontrol.currentPageIndicatorTintColor = [UIColor redColor];
    
    
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
       self.pagecontrol.currentPage = scrollView.contentOffset.x/375;
}


@end
           